package com.rjwh.dingdong.client.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.aishua.lib.utils.AsStrUtils;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.rjwh.dingdong.client.R;
import com.rjwh.dingdong.client.bean.localbean.RadioPageMenuData;
import com.rjwh.dingdong.client.util.UrlUtil;
import com.rjwh.dingdong.client.util.ViewHolder;
import com.rjwh.dingdong.client.widget.RoundImageView;

/**
 * @author Kay
 * @ClassName RadioPageMenuGridAdapter
 * @Description
 * @date 2016-10-26
 * @history 2016-10-26 author: description:
 */

public class RadioPageMenuGridAdapter extends AdapterBase<RadioPageMenuData> {

    private Context mContext;

    public RadioPageMenuGridAdapter(Context mContext) {
        this.mContext = mContext;
    }

    @Override
    protected View getExView(int position, View convertView, ViewGroup parent) throws Exception {
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.radio_menu_grid_item, null);
        }

        RoundImageView radioMenuGridItemImg = ViewHolder.get(convertView, R.id.radio_menu_grid_item_img);
        TextView radioMenuGridItemTv = ViewHolder.get(convertView, R.id.radio_menu_grid_item_tv);
        RadioPageMenuData radioPageMenuData = getList().get(position);

        if (radioPageMenuData == null) {
            return convertView;
        }

        String menuname = radioPageMenuData.getMenuname();
        String menuicon = radioPageMenuData.getMenuicon();

        if (!AsStrUtils.isEmpty(menuname)) {
            radioMenuGridItemTv.setText(menuname);
        }

        Glide.with(mContext).load(menuicon).dontAnimate().placeholder(R.drawable.icon_pic_holder).error(R.drawable.icon_pic_holder)
                .diskCacheStrategy(DiskCacheStrategy.ALL).into(radioMenuGridItemImg);

        return convertView;
    }

}
